package com.rjwh.dingdong.client.util;

import com.aishua.lib.utils.AsStrUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ContactPhoneUtils {
    /**
     * 去除电话号码 前缀�?-
     *
     * @return 处理后的电话号码
     */
    public static String formatNumber(String number) {
        String returnStr;
        if (number == null || number.length() == 0) {
            return null;
        }
        returnStr = number.replaceAll("-", "");
        if (returnStr.startsWith("+86")) {
            return returnStr.substring(3, number.length());
        } else if (returnStr.startsWith("17951")) {
            return returnStr.substring(5, number.length());
        } else if (returnStr.startsWith("12593")) {
            return returnStr.substring(5, number.length());
        } else if (returnStr.startsWith("17911")) {
            return returnStr.substring(5, number.length());
        } else if (returnStr.startsWith("17900")) {
            return returnStr.substring(5, number.length());
        } else {
            return returnStr;
        }
    }

    /**
     * 处理首字�?
     *
     * @return 字符串的首字母，不是A~Z范围的返�?#
     */
    public static String formatAlpha(String str) {
        if (str == null) {
            return "#";
        }
        if (str.trim().length() == 0) {
            return "#";
        }

        char c = str.trim().substring(0, 1).charAt(0);
        Pattern pattern = Pattern.compile("^[A-Za-z]+$");
        if (pattern.matcher(c + "").matches()) {
            return (c + "").toUpperCase();
        } else {
            return "#";
        }
    }

    /**
     * 判断手机号是否合法
     *
     * @param @param  mobiles
     * @param @return
     * @return boolean
     * @throws
     * @Title: isMobileNO
     * @Description: TODO(这里用一句话描述这个方法的作用)
     * @history 1.YYYY-MM-DD author: description:
     */
    public static boolean isMobileNO(String mobiles) {
        Pattern p = Pattern.compile("^1[3,4,5,7,8]\\d{9}$");
        Matcher m;
        if (AsStrUtils.isEmpty(mobiles)) {
            return false;
        } else {
            m = p.matcher(mobiles);
        }
        return m.matches();
    }
}
